from io import BytesIO
from PyQt5.QtGui import QPixmap, QIcon
from pytablericons import TablerIcons, OutlineIcon


def icon_handled(img):
    # 1. Pillow Image -> PNG 字节流
    # img = TablerIcons.load(OutlineIcon.FOLDER_OPEN, size=24, color='#222')
    buf = BytesIO()
    img.save(buf, format='PNG')
    buf.seek(0)

    # 2. 字节流 -> QPixmap
    pixmap = QPixmap()
    pixmap.loadFromData(buf.getvalue())
    return pixmap
